const { sendServer } = require("../../../request/common");

// pages/pay/payDone/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    methods:'',
    totalPrice:'',
    orderId:"",
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let totalPrice=options.totalPrice
    let orderId=options.orderId
    this.setData({
      totalPrice:totalPrice,
      orderId:orderId
    })
  },
  onShow: function () {

  },
  onChange(event) {
    this.setData({
      methods: event.detail,
    });
  },

  onClick(event) {
    const { name } = event.currentTarget.dataset;
    this.setData({
      methods: name,
    });
  },
  payDone(){
    if(this.nextTap){
      return;
    }
    this.nextTap=true;
    let that=this;
    setTimeout(()=>{
      that.nextTap=false;
    },1000)
    let params={},send={}
    send.orderId=this.data.orderId;
    send.paymethod=this.data.methods;
    params.send=send;
    params.url="order/payOver";
    sendServer(params,(commRes)=>{
      if(commRes.code==100){
        var time=new Date().getTime()
        let order=commRes.extend.order
        let address=order.address.address+order.address.detail
        let params={},send={};
        send.orderId=order.orderId;
        send.userId=order.userId;
        send.totalprice=order.totalprice;
        send.address=address//收货地址
        send.postcode=order.address.postcode;
        send.recePhone=order.address.recePhone;
        send.receName=order.address.receName;
        send.deliverymethod=order.deliverymethod;
        send.memo=order.memo;
        send.createTime=time
        send.paymethod=order.paymethod;
        send.status=1;//1表示已付款
        send.item=JSON.stringify(order.orderItemList);
        params.send=send;
        params.url="bgorder/toBgOrder";
        sendServer(params,(commRes)=>{
          if(commRes.code==100){
            wx.showToast({
              title: '支付成功',
              icon:"success",
              duration:3000
            })
            wx.navigateTo({
              url: '/pages/order/orderDetail/index?orderId='+send.orderId,
            })
          }
        })
      }
    })
  },
})